package com.slkj.shilixiaoyuanapp.util;

import android.text.BoringLayout;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static android.text.TextUtils.isEmpty;

public class TxtUtil {
    private static final String PHONE = "^1[3|4|5|7|8][0-9]\\d{8}$";
    private static final String COVER_LESS_TWO_WORD = "^(((?=.*[0-9])(?=.*[a-zA-Z])|(?=.*[0-9])(?=.*[^\\s0-9a-zA-Z])|(?=.*[a-zA-Z])(?=.*[^\\s0-9a-zA-Z]))[^\\s]+)&#36";
    private static final String COVER_THREE_WORD = "^(?i).+(?<=\\d.*)(?<=[a-z].*)(?<=[^a-z\\s\\d].*)&#36";
    /**
     * 是否是移动电话号码
     * 只验证了开始的数字和长度
     */
    public static boolean isMobileNum(String mobiles) {
        if (isEmpty(mobiles)) return false;
        Pattern pattern = Pattern.compile(PHONE);
        Matcher matcher = pattern.matcher(mobiles);
        return matcher.matches();
//        if (mobiles.trim().length() == 11 && !mobiles.trim().isEmpty()) {
//            if ("1".equals(mobiles.substring(0, 1))) {
//                return true;
//            } else {
//                return false;
//            }
//        }
//        return false;
    }
    /**
     * 手机号 星号处理    asterisk（星号）
     */
    public static String asteriskUserPhone(String mobiles) throws NullPointerException, StringIndexOutOfBoundsException {
        if (isEmpty(mobiles) || mobiles.length() < 11) return "";
        return mobiles.substring(0, 3) + "****" + mobiles.substring(7, mobiles.length());
    }
    /*
    * 至少包含“数字”,“字母”,“特殊字符”中的两种
    * */
    public static boolean isCoverTwoWord(String pwd){
        if (isEmpty(pwd)) return false;
        Pattern compile = Pattern.compile(COVER_LESS_TWO_WORD);
        Matcher matcher = compile.matcher(pwd);
        return matcher.matches();
    }
    /*
     * 包含“数字”,“字母”,“特殊字符”三种
     * */
    public static boolean isCoverThreeWord(String pwd){
        if (isEmpty(pwd)) return false;
        Pattern compile = Pattern.compile(COVER_THREE_WORD);
        Matcher matcher = compile.matcher(pwd);
        return matcher.matches();
    }
}
